package com.meishi.restaurant.dao.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.meishi.restaurant.dao.RestaurantDAO;
import com.meshi.hibernate.dao.CommonDAO;
import com.meishi.restaurant.Restaurant;

public class RestaurantDAOImpl 
	           implements RestaurantDAO {

	private Session session;
	
	public void setSession(Session session) {
		this.session = session;
	}


	@Override
	public void create(Restaurant r) {
		// TODO Auto-generated method stub
		Transaction tx = session.beginTransaction();
		session.save(r);
		tx.commit();
	}

	@Override
	public void delete(Restaurant r) {
		// TODO Auto-generated method stub
		Transaction tx = session.beginTransaction();
		session.delete(r);
		tx.commit();
	}

	@Override
	public void update(Restaurant r) {
		// TODO Auto-generated method stub
		Transaction tx = session.beginTransaction();
		session.update(r);
		tx.commit();
	}


	@Override
	public Restaurant get(long id) {
		// TODO Auto-generated method stub
		Transaction tx = session.beginTransaction();
		Restaurant r = (Restaurant) session.get(Restaurant.class, id);
		tx.commit();
		return r;
	}
}
